<?php
/**
 * User: lsx
 * Date: 2017/6/24
 * Time: 11:42
 * Progress:0%
 */

namespace logic\admin\index;
use model\AccountLog;
use model\Account;
use think\Db;

class LAccountLog
{
    //余额更改日志列表
    public function index_data($param){
        $model = new AccountLog();
        $where=array();
        $search =$param['search'];
        if (!empty($search)) {
            $where['a.nick'] = array('like', "%{$search}%"); //查询条件
        }
        //1：余额修改
        $where['l.type'] = 1;

        //记录总数
        $total = $model->alias('l')
            ->join('account a','a.id = l.account_id','left')
            ->where($where)
            ->count();
        $page_size =$param['limit']; //获取分页数
        $start = $param['offset']; //获取开始的记录数
        //获取排序字段------------------------------------------------------------开始

        $sort_name = $param['ordinal'];
        $sort_desc = $param['order'];

        if (!empty($sort_name)) {
            $sort[$sort_name] = $sort_desc;
        } else {
            $sort['l.create_time'] = 'desc'; //默认排序
        }
        //获取排序字段------------------------------------------------------------结束

        $rows = $model->alias('l')
            ->join('account a','a.id = l.account_id','left')
            ->join('admin a2','a2.id = l.operation_id','left')
            ->field('l.*,a.name as account_name,a.nick as account_nick,a2.name as operation_name')
            ->where($where)
            ->limit($start, $page_size)
            ->order($sort)
            ->select();

        $array=array(
            'total'=>$total,
            'rows'=>$rows
        );

        return $array;

    }
}